home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / progutil / stdwin.zoo / test / multiwin.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-03-30  |  2.0 KB  |  128 lines

  1. /* Multiple windows, menus */
  2.  
  3. #include "stdwin.h"
  4.  
  5. #define NW 10            /* Max # of windows */
  6.  
  7. struct {
  8.     WINDOW *win;
  9.     TEXTEDIT *tb;
  10.     int bottom;
  11. } wlist[NW];            /* Window list */
  12.  
  13. void
  14. drawproc(win, l, tl, r, b)
  15.     WINDOW *win;
  16. {
  17.     int i= wgettag(win);
  18.     tedraw(wlist[i].tb);
  19. }
  20.  
  21. newwin()
  22. {
  23.     int i;
  24.     
  25.     for (i= 0; i < NW; ++i) {
  26.         if (wlist[i].win == 0) {
  27.             char title[20];
  28.             int width, height;
  29.             WINDOW *win;
  30.             sprintf(title, "Untitled-%d", i);
  31.             wlist[i].win= win= wopen(title, drawproc);
  32.             wsettag(win, i);
  33.             wgetwinsize(win, &width, &height);
  34.             wlist[i].tb= tealloc(win, 0, 0, width);
  35.             wlist[i].bottom= tegetbottom(wlist[i].tb);
  36.             wsetdocsize(win, width, wlist[i].bottom);
  37.             return;
  38.         }
  39.     }
  40.     
  41.     wmessage("Can't open another window");
  42. }
  43.  
  44. closewin(win)
  45.     WINDOW *win;
  46. {
  47.     int i= wgettag(win);
  48.     tefree(wlist[i].tb);
  49.     wclose(wlist[i].win);
  50.     wlist[i].win= 0;
  51. }
  52.  
  53. main(argc, argv)
  54.     int argc;
  55.     char **argv;
  56. {
  57.     MENU *mp;
  58.     int inew, iquit;
  59.     int stop= 0;
  60.     
  61.     winitnew(&argc, &argv);
  62.     
  63.     mp= wmenucreate(1, "File");
  64.     inew= wmenuadditem(mp, "New", 'N');
  65.     (void) wmenuadditem(mp, "", -1);
  66.     iquit= wmenuadditem(mp, "Quit", 'Q');
  67.     
  68.     newwin();        /* Initial window */
  69.     
  70.     while (!stop) {
  71.         EVENT e;
  72.         
  73.         wgetevent(&e);
  74.         
  75.         if (e.window != 0) {
  76.             int i= wgettag(e.window);
  77.             if (teevent(wlist[i].tb, &e)) {
  78.                 /*if (tegetbottom(wlist[i].tb) !=
  79.                         wlist[i].bottom)*/
  80.                 wsetdocsize(wlist[i].win,
  81.                     tegetright(wlist[i].tb),
  82.                     tegetbottom(wlist[i].tb));
  83.                 continue;
  84.             }
  85.         }
  86.         
  87.         switch (e.type) {
  88.         
  89.         case WE_MENU:
  90.             switch (e.u.m.id) {
  91.             case 1:
  92.                 if (e.u.m.item == inew)
  93.                     newwin();
  94.                 else if (e.u.m.item == iquit)
  95.                     stop= 1;
  96.                 break;
  97.             }
  98.             break;
  99.         
  100.         case WE_COMMAND:
  101.             switch (e.u.command) {
  102.             
  103.             case WC_CLOSE:
  104.                 closewin(e.window);
  105.                 break;
  106.             
  107.             }
  108.             break;
  109.         
  110.         case WE_SIZE:
  111.             {
  112.                 int i= wgettag(e.window);
  113.                 int width, height;
  114.                 wgetwinsize(e.window, &width, &height);
  115.                 temove(wlist[i].tb, 0, 0, width);
  116.                 wlist[i].bottom= tegetbottom(wlist[i].tb);
  117.                 wsetdocsize(wlist[i].win,
  118.                     width, wlist[i].bottom);
  119.             }
  120.             break;
  121.         }
  122.     }
  123.     
  124.     wdone();
  125.     exit(0);
  126. }
  127.  
  128.